package com.res.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.res.entity.Department;
import com.res.entity.Teacher;
import com.res.service.TeacherService;
import com.res.util.FenyeUtil;

@RestController
@RequestMapping("/teacher")
public class TeacherController {
	@Autowired
	private TeacherService tff;
	@GetMapping
	public FenyeUtil<Teacher> GetTeach(Teacher t,Integer did,Integer page,Integer limit){
		Pageable p = PageRequest.of(page-1, limit+1);
		return tff.GetTeachByPage(t, did, p);
	}
	@PostMapping
	public Integer AddAndUpd(Teacher t,Department d) {
		t.setDepartment(d);
		return tff.AddAndUpd(t);
	}
	@DeleteMapping
	public Integer Del(Integer tid) {
		return tff.Del(tid);
	}
	@GetMapping
	@RequestMapping("/getdep")
	public List<Department> get(){
		return tff.GetAll();
	}
}
